package com.yw.controller;

import com.yw.ScriptInfo.dto.QueryScriptDTO;
import com.yw.interfaceManageInfo.dto.UpdateTypeBatchDTO;
import com.yw.piliangDTO.StatusDTO;
import com.yw.result.R;
import com.yw.service.TaskService;
import com.yw.task.dto.AddTaskDTO;
import com.yw.task.dto.ExecuteTaskDTO;
import com.yw.task.dto.TaskQueryDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Tag(name = "任务管理",description = "任务管理")
@RequestMapping("/task")
public class TaskController {

    @Resource
    private TaskService taskService;

    @Operation(summary = "添加任务")
    @PostMapping("/addTask")
    private R addTask(@RequestBody AddTaskDTO addTaskDTO){
       return taskService.addTask(addTaskDTO)?R.OK():R.FAIL();
    }

    @Operation(summary = "条件查询任务")
    @PostMapping("/queryTask")
    public R queryTask(@RequestBody TaskQueryDTO taskQueryDTO){
        return R.OK(taskService.queryTask(taskQueryDTO));
    }


    @Operation(summary = "执行任务")
    @PostMapping("/executeTask")
    public R executeTask(@RequestBody String taskName){
        return R.OK(taskService.executeTask(taskName));
    }
    @Operation(summary = "删除任务")
    @PostMapping("/deleteTask")
    public R deleteTask(Integer id){return taskService.removeById(id)?R.OK():R.FAIL();}

    //    批量发布停用
    @Operation(summary = "批量发布停用")
    @PostMapping("/batch")
    public R batch(@RequestBody StatusDTO statusDTO){
        return taskService.batch(statusDTO)?R.OK("批量发布成功"):R.FAIL("批量发布失败");
    }

    //    批量修改类型
    @Operation(summary = "批量修改类型")
    @PostMapping("/updateTypeBatch")
    public R updateTypeBatch(@RequestBody UpdateTypeBatchDTO updateTypeBatchDTO){
        return taskService.updateTypeBatch(updateTypeBatchDTO.ids,updateTypeBatchDTO.type)?R.OK("批量发布成功"):R.FAIL("批量发布失败");
    }

}
